package com.fire.core.service;

import com.fire.core.mode.TMitUserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class CkeckTokenService {
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    RedisService redisService;
    /**
     * token校验 并返回用户信息
     */

    public TMitUserToken ckeckToken(String token) {
        boolean flag=redisService.exists(token);
        TMitUserToken userToken=null;
        // 验证token是否超时
        if(flag) {
            Long oldDate = redisTemplate.getExpire(token, TimeUnit.MINUTES);
            if (oldDate > 0) {
                userToken = (TMitUserToken) redisTemplate.opsForValue().get(token);

            }
        }
        return userToken;
    }
}
